浏览量 4358
2019/08/19 20:43
shell 交互 git 批量备份
安装expect
yum install expect
编写免输入脚本
#!/usr/bin/expect
set timeout 10
set git_host [lindex $argv 0]
spawn git clone $git_host
expect "Username*"
send "myname\n"
expect "Password*"
send "mypassword\n"
expect "100%"
expect eof
批量脚本
#!/bin/bash
cd /data/git && mkdir `date +%Y%m%d` && cd `date +%Y%m%d`
if [ $? != 0 ];then
exit 1
fi
expect /data/git/gitpull.exp https://git.1.git
expect /data/git/gitpull.exp https://git.2.git
expect /data/git/gitpull.exp https://git.3.git
......
定时备份
0 3 * * * /data/git/git_clone.sh > `date +%Y%m%d`.log 2>&1 &
结果
4.6G 20190819
2.0M 20190819.log
28K git_clone.sh
4.0K gitpull.exp
定时删除
0 5 * * * find /data/git/`date +\%Y\%m\%d --date="-8 day"` |xargs rm -rf > /dev/null 2>&1 &
上一篇
搜索
下一篇